package com.zlfund.cat.zjgsmk.net;

import com.zlfund.cat.zjgsmk.constant.HttpUrl;

import retrofit2.CallAdapter;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by chenj
 * Created on 2017/8/19
 */

public class RetrofitFactory {

    public static Retrofit createGsonAndRxRetrofit(){
        return createRetrofit(HttpUrl.CC_HTTP,GsonConverterFactory.create(),RxJava2CallAdapterFactory.create());
    }

    public static Retrofit createGsonRetrofit(){
        return createRetrofit(HttpUrl.CC_HTTP,GsonConverterFactory.create(),null);
    }

    public static Retrofit createRetrofit(){
        return createRetrofit(HttpUrl.CC_HTTP,null,null);
    }

    private static Retrofit createRetrofit(String baseUrl, Converter.Factory convertFactory, CallAdapter.Factory callAdapterFactory){
        Retrofit.Builder builder = new Retrofit.Builder().baseUrl(baseUrl);
        if (convertFactory != null) builder.addConverterFactory(convertFactory);
        if (callAdapterFactory != null) builder.addCallAdapterFactory(callAdapterFactory);
        return builder.build();
    }
}
